class CreateCommonObjects < ActiveRecord::Migration
  def self.up
    begin
      tags_up()
      identifiers_up()
      images_up()
      links_up()
      link_types_up()
      comments_up()
      locations_up()
      location_maps_up()
    rescue
      puts "Did not actually create all tables: " + $!
    end
  end

  def self.down
    begin  drop_table :tags           rescue puts "Failed to drop: " + $! end
    begin  drop_table :identifiers    rescue puts "Failed to drop: " + $! end
    begin  drop_table :images         rescue puts "Failed to drop: " + $! end
    begin  drop_table :images_tags    rescue puts "Failed to drop: " + $! end
    begin  drop_table :links          rescue puts "Failed to drop: " + $! end
    begin  drop_table :link_types     rescue puts "Failed to drop: " + $! end
    begin  drop_table :comments       rescue puts "Failed to drop: " + $! end
    begin  drop_table :locations      rescue puts "Failed to drop: " + $! end
    begin  drop_table :location_maps  rescue puts "Failed to drop: " + $! end
  end

  def self.tags_up
    create_table :tags do |t|
      t.string :name
      t.timestamps
    end
  end

  def self.identifiers_up
    create_table :identifiers do |t|
      t.string :name
      t.string :type
      t.timestamps
    end
  end

  def self.images_up
    create_table :images do |t|
      t.string :name
      t.string :image_type
      t.string :image_rating
      t.string :location
      t.timestamps
    end

    create_table :images_tags, :id => false do |t|
      t.integer :image_id
      t.integer :tag_id
    end
  end

  def self.links_up
    create_table :links do |t|
      t.string :url
      t.string :link_type
      t.timestamps
    end
  end

  def self.link_types_up
    create_table :link_types do |t|
      t.string  :name
      t.integer :int_type
      t.timestamps
    end
  end

  def self.comments_up
    create_table :comments do |t|
      t.string :name

      t.timestamps
    end
  end

  def self.locations_up
    create_table :locations do |t|
      t.string  :name
      t.integer :parent_id 
      t.timestamps
    end
  end

  def self.location_maps_up
    create_table :location_maps do |t|
      t.string  :name
      t.timestamps
    end
  end
end
